(function($){ 
	$.popeWin = function(options){ 
		var defaults = { 
			id:"", 
			className:"",
			content:"",
			width:0.5,
			height:0.8,
			widthpx:0,
			heightpx:0,
			top:"",
			left:"",
			pos:"center",
			closeImg:"",
			url:""
		};
		var options = $.extend(defaults, options); 
		var id = options.id;
		var winheight = $(window).height();
		var winwidth = $(window).width();
		$("#msgdiv").overlay({
			effect: 'fade',
			opacity: 0.8,
			closeOnClick: true,
			onShow: function() {
				


				if($("#"+id).length!=0){
			
					$("#"+id).show();
					return;
				}

				var loading = '<img id="loadingImg" src="image/preload.gif" style="width:90px;height:90px;margin-top:'+(winheight/2-45)+'px;margin-left:'+(winwidth/2-45)+'px;" >';
				$('.overlay').append(loading);

				var classname = options.className;
				var con = options.content;
				var w = winwidth * options.width;
				var h = winheight * options.height;
				if(options.widthpx!=0){
					w = options.widthpx;
				}
				if(options.heightpx!=0){
					h = options.heightpx;
				}

				var l = (winwidth - w)/2;
				var t = (winheight - h)/2;

				
				
				
				var box = '<div id="'+id+'" boxw="'+options.width+'" boxh="'+options.height+'" class="popeBox '+classname+'" style="z-index:5000;position: fixed;display:none;"><div onclick="$.popeWinClose({id:\''+id+'\'});" style="position: fixed;margin-left:-15px;margin-top:-15px;z-index:5001;width:30px;height:30px;"><img src="'+options.closeImg+'" style="width:30px;height:30px;cursor:pointer;"></div><iframe onload="$(\'#loadingImg\').remove();$(\'#'+id+'\').show();" id="iframe_'+id+'" style="width:100%;height:100%;" class="popeFrame"  allowtransparency="true" scrolling="no" frameBorder="0" src="'+options.url+'"></iframe></div>';
				
				$("body").append(box);
				$("#"+id).css("width",w);
				$("#"+id).css("height",h);
				$("#"+id).css("top",t);
				$("#"+id).css("left",l);
				setTimeout('$("#loadingImg").remove();$("#'+id+'").show();',2000);
			},
			onHide: function() {
				$("#loadingImg").remove();
				$("#"+id).hide();
			}
		});
		

		this.each(function(){ 
			
			
		}); 
	}; 
	$.popeWinClose = function(options){ 
		var defaults = { 
			id:""
		};
		var options = $.extend(defaults, options); 
		var id = options.id;
		$("#"+id).hide();
		$("#"+id).remove();
		$(".overlay").click();
		$("#"+id+"_imgTool").remove();
		refreshImgTool();


		this.each(function(){ 
			
			
		}); 
	};

	$.popeWinRefreash = function(options){ 
		var defaults = { 
			id:""
		};
		var options = $.extend(defaults, options); 
		var id = options.id;
		if(id==null||id==""){
			return;
		}
		var winheight = $(window).height();
		var winwidth = $(window).width();
		var bw = parseFloat($("#"+id).attr("boxw"));
		var bh = parseFloat($("#"+id).attr("boxh"));
		var w = winwidth * bw;
		var h = winheight * bh;
		var l = (winwidth - w)/2;
		var t = (winheight - h)/2;
		
		$("#"+id).css("width",w);
		$("#"+id).css("height",h);
		$("#"+id).css("top",t);
		$("#"+id).css("left",l);


		this.each(function(){ 
			
			
		}); 
	};

	$.popeWinResize = function(options){ 
		var defaults = { 
			id:"",
			width:0.5,
			height:0.8,
			widthpx:0,
			heightpx:0
		};
		
		var options = $.extend(defaults, options); 
		var id = options.id;
		if(id==null||id==""){
			return;
		}
		var winheight = $(window).height();
		var winwidth = $(window).width();

		var w = winwidth * options.width;
		var h = winheight * options.height;
		
		if(options.widthpx!=0){
			
			w = options.widthpx;
		}
		if(options.heightpx!=0){
			h = options.heightpx;
		}
		
		var l = (winwidth - w)/2;
		var t = (winheight - h)/2;

		$("#"+id).attr("boxw",options.width);
		$("#"+id).attr("boxh",options.height);
		
		//$("#"+id).css("width",w);
		//$("#"+id).css("height",h);
		//$("#"+id).css("top",t);
		//$("#"+id).css("left",l);

		$("#"+id).animate({
			width: w,
			height: h,
			left: l,
			top:t
		}, 500 );
		


		this.each(function(){ 
			
			
		}); 
	};

	$.popeWinMini = function(options){ 
		var defaults = { 
			id:"",
			width:300,
			height:400,
			url:"",
			content:""
		};
		var options = $.extend(defaults, options); 
		var id = options.id;
		if(id==null||id==""){
			return;
		}
		var box;
		if(options.url!=null&&options.url!=""){
			box='<div id="miniWin_'+id+'" class="popeWinMini" style="width:'+options.width+'px;height:'+options.height+'px"  ><div class="popeWinMiniBox1"></div><div class="popeWinMiniBox" ><iframe   style="width:100%;height:100%;"  allowtransparency="true" scrolling="no" frameBorder="0" src="'+options.url+'"></iframe></div></div>';
		}else{
			if(options.content!=null&&options.content!=""){
				box='<div id="miniWin_'+id+'" class="popeWinMini" style="width:'+options.width+'px;height:'+options.height+'px"  ><div class="popeWinMiniBox1"></div><div class="popeWinMiniBox" >'+options.content+'</div></div>';
			}else{
				box='<div id="miniWin_'+id+'" class="popeWinMini" style="width:'+options.width+'px;height:'+options.height+'px"  ><div class="popeWinMiniBox1"></div><div class="popeWinMiniBox" >无内容</div></div>';
			}
		} 
		$("body").append(box);
		var l = parseFloat($("#"+id).offset().left);
		var t = parseFloat($("#"+id).offset().top);
		var h = parseFloat($("#"+id).css("height"));
		
		

		$("#miniWin_"+id).css("left",l);
		$("#miniWin_"+id).css("top",t+h+2);
		$("#miniWin_"+id).show("blind",null,300,null);

		this.each(function(){ 
			
			
		}); 
	};

	$.popeWinMiniClose = function(options){ 
		var defaults = { 
			id:""
			
		};
		var options = $.extend(defaults, options); 
		var id = options.id;
		if(id==null||id==""){
			return;
		}
		
		$("#miniWin_"+id).hide("blind",null,300,function(){
			$("#miniWin_"+id).remove();
		});
		

		this.each(function(){ 
			
			
		}); 
	};
	$.popeWinMiniResize = function(options){ 
		var defaults = { 
				id:"",
				width:0.5,
				height:0.8,
				widthpx:0,
				heightpx:0
				
			};
			var options = $.extend(defaults, options); 
			var id = options.id;
			if(id==null||id==""){
				return;
			}
			var winheight = $(window).height();
			var winwidth = $(window).width();

			var w = winwidth * options.width;
			var h = winheight * options.height;
			
			if(options.widthpx!=0){
				
				w = options.widthpx;
			}
			if(options.heightpx!=0){
				h = options.heightpx;
			}
			


			$("#"+id).animate({
				width: w,
				height: h
			}, 500 );
			

			this.each(function(){ 
				
				
			}); 
		};
	
})(jQuery); 


